<template>
	<view class="container">
		<u-toast ref="uToast"></u-toast>
		<view class="box">
			<view class="one">
				1.是否漏水?
			</view>
			<view class="two">
				<u-radio-group v-model="radioValue1" placement="column">
					<u-radio :customStyle="{marginBottom: '20px'}" v-for="item in radiolist1" :key="item.value"
						:label="item.name" :name="item.value" @change="radioChange">
					</u-radio>
				</u-radio-group>
			</view>
		</view>
		<view class="box">
			<view class="one">
				2.是否漏电?
			</view>
			<view class="two">
				<u-radio-group v-model="radioValue2" placement="column">
					<u-radio :customStyle="{marginBottom: '20px'}" v-for="item in radiolist1" :key="item.value"
						:label="item.name" :name="item.value" @change="radioChange2">
					</u-radio>
				</u-radio-group>
			</view>
		</view>
		<view class="butt">
			<u-button type="warning" text="发现隐患，点击上传" @click="Tanager" class='but' :plain="true"></u-button>
			<u-button type="primary" text="提交" @click="submit" class='but'></u-button>
		</view>
	</view>
</template>

<script>
	import {
		startInspectionAPI
	} from '@/api/api.js'
	export default {
		data() {
			return {
				type: null,
				info: null,
				radiolist1: [{
						name: '发现隐患',
						value: 1
					},
					{
						name: '未发现隐患',
						value: 0
					},
				],
				radioValue1: '',
				radioValue2: '',
				form: {
					isFxyh: 0
				}
			}
		},
		onLoad(option) {
			this.info = option.details
			this.type = option.type
		},
		mounted() {
			this.form = {
				...JSON.parse(this.info)
			}
			console.log(this.form);
		},
		methods: {
			Tanager() {
				uni.navigateTo({
					url: `/pages/inspection/dangerSubmit/dangerSubmit2/dangerSubmit2?form=${JSON.stringify(this.form)}&type=${this.type}`
				})
			},
			radioChange(n) {
				this.radioValue1 = n
			},
			radioChange2(n) {
				this.radioValue2 = n
			},
			submit() {
				if ((this.radioValue1 === 0 && this.radioValue2 === 0)) {
					this.form.isFxyh = 0
					startInspectionAPI({
						...this.form,
						type: this.type,
					}).then((r) => {
						if (r.code === 200) {
							this.$refs.uToast.show({
								type: 'success',
								title: '新增成功',
								message: "新增成功",
								iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
							})
							setTimeout((e) => {
								uni.navigateBack({
									delta: 2
								})
							}, 2000)
						}
					})
				}
				if (this.radioValue1 === 1 || this.radioValue2 === 1) {
					this.form.isFxyh = 1
					this.$refs.uToast.show({
						type: 'error',
						position: 'top',
						message: "请上传隐患内容",
						iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.container {
		height: calc(100vh - 40px);
		padding: 40rpx 24rpx;
		background-color: #f6f6f6;
	}

	.box {
		background-color: #fff;
		padding: 30rpx;
		border-radius: 20rpx;
		margin-bottom: 30rpx;

		.one {
			padding-bottom: 30rpx;
			border-bottom: 1rpx solid #f6f6f6;
			margin-bottom: 20rpx;
		}
	}

	.but {
		margin-top: 30rpx;
	}
</style>
